<!--
This software was developed at The MITRE Corporation 
in 2004/2006 and has been approved for Public Release; Distribution Unlimited.


		    GNU GENERAL PUBLIC LICENSE
		       Version 2, June 1991

 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
                       51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

			    Preamble

  The licenses for most software are designed to take away your
freedom to share and change it.  By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software-to make sure the software is free for all its users.  This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it.  (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.)  You can apply it to
your programs, too.

  When we speak of free software, we are referring to freedom, not
price.  Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.

  To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

  For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have.  You must make sure that they, too, receive or can get the
source code.  And you must show them these terms so they know their
rights.

  We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

  Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software.  If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.

  Finally, any free program is threatened constantly by software
patents.  We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary.  To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.

  The precise terms and conditions for copying, distribution and
modification follow.

		    GNU GENERAL PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License.  The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language.  (Hereinafter, translation is included without limitation in
the term "modification".)  Each licensee is addressed as "you".

Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope.  The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.

  1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.

You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.

  2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:

    a) You must cause the modified files to carry prominent notices
    stating that you changed the files and the date of any change.

    b) You must cause any work that you distribute or publish, that in
    whole or in part contains or is derived from the Program or any
    part thereof, to be licensed as a whole at no charge to all third
    parties under the terms of this License.

    c) If the modified program normally reads commands interactively
    when run, you must cause it, when started running for such
    interactive use in the most ordinary way, to print or display an
    announcement including an appropriate copyright notice and a
    notice that there is no warranty (or else, saying that you provide
    a warranty) and that users may redistribute the program under
    these conditions, and telling the user how to view a copy of this
    License.  (Exception: if the Program itself is interactive but
    does not normally print such an announcement, your work based on
    the Program is not required to print an announcement.)

These requirements apply to the modified work as a whole.  If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works.  But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.

Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.

In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.

  3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:

    a) Accompany it with the complete corresponding machine-readable
    source code, which must be distributed under the terms of Sections
    1 and 2 above on a medium customarily used for software
    interchange; or,

    b) Accompany it with a written offer, valid for at least three
    years, to give any third party, for a charge no more than your
    cost of physically performing source distribution, a complete
    machine-readable copy of the corresponding source code, to be
    distributed under the terms of Sections 1 and 2 above on a medium
    customarily used for software interchange; or,

    c) Accompany it with the information you received as to the offer
    to distribute corresponding source code.  (This alternative is
    allowed only for noncommercial distribution and only if you
    received the program in object code or executable form with such
    an offer, in accord with Subsection b above.)

The source code for a work means the preferred form of the work for
making modifications to it.  For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable.  However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.

If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.

  4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License.  Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.

  5. You are not required to accept this License, since you have not
signed it.  However, nothing else grants you permission to modify or
distribute the Program or its derivative works.  These actions are
prohibited by law if you do not accept this License.  Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.

  6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions.  You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.

  7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License.  If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all.  For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.

If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.

It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices.  Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.

This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.

  8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded.  In such case, this License incorporates
the limitation as if written in the body of this License.

  9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time.  Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.

Each version is given a distinguishing version number.  If the Program
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation.  If the Program does not specify a
version number of this License, you may choose any version ever
published by the Free Software Foundation.

  10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission.  For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this.  Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.

			    NO WARRANTY

  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.

		     END OF TERMS AND CONDITIONS

	    How to Apply These Terms to Your New Programs

  If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these
terms.

  To do so, attach the following notices to the program.  It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA


Also add information on how to contact you by electronic and paper mail.

If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:

    Gnomovision version 69, Copyright (C) year name of author
    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
    This is free software, and you are welcome to redistribute it
    under certain conditions; type `show c' for details.

The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License.  Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items-whatever suits your program.

You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary.  Here is a sample; alter the names:

  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
  `Gnomovision' (which makes passes at compilers) written by James Hacker.

  <signature of Ty Coon>, 1 April 1989
  Ty Coon, President of Vice

This General Public License does not permit incorporating your program into
proprietary programs.  If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library.  If this is what you want to do, use the GNU Library General
Public License instead of this License.
-->
<body>
<b>Graphical User Interface</b> - Control and visibility of Tortuga simulation execution.

<h3>Contents</h3>
<blockquote>
<ul>
  <li><a href="#Introduction"><b>Introduction</b></a>
  <ul>
	<li><a href="#BasicControls"><b>Basic Controls</b></a>
	<li><a href="#SimulationTime"><b>Simulation Time</b></a>
  </ul>
  <li><a href="#PlugInDisplays"><b>Plug-in Displays</b></a>
  <ul>
 	<li><a href="#LogDisplay"><b>Log Display</b></a>
 	<li><a href="#ProbeDisplay"><b>Probe Display</b></a>
 	<li><a href="#PopulationDisplay"><b>Population Display</b></a>
  </ul>
  <li><a href="#PropertyFileParameters"><b>Property File Parameters</b></a>
</ul>
</blockquote>

<a name="Introduction"/>
<h2>Introduction</h2>

The Tortuga framework, {@link org.mitre.sim}, offers a graphical user interface (GUI) that provides control over
an executing simulation and visibility into its activity.
The GUI display is turned on and off with
{@link org.mitre.sim.Simulation#setVisible(boolean) Simulation.setVisible(boolean)}.
The GUI is off by default.
(Note: If the GUI is displayed,
{@link org.mitre.sim.Simulation#run() Simulation.run()}
should not be called.)
<p>
<table cols=1 border=1>
  <tr bgcolor="#99cccc"><td>
<h3>Example: Making the GUI Visible</h3>
A handy way to use the GUI is to turn it on when a
{@link org.mitre.sim.Simulation Simulation} instance is created.
<blockquote>
<pre>
<b>public class</b> MySimulation <b>extends</b> Simulation {

  <b>public void</b> initialize() {
    ...
  }

  <b>public static void</b> main(String[] args) {
    <b>new</b> MySimulation().{@link org.mitre.sim.Simulation#setVisible(boolean) setVisible}(<b>true</b>);
  }
}
</pre>
</blockquote>
</td></tr></table>

<a name="BasicControls"/>
<h3>Basic Controls</h3>

By default, the GUI displays controls to start, play, and pause the simulation,
and to control the simulation pace.
Properties can be placed in the sim.properties resource file to control many aspects of the GUI.
The system default properties produce the display shown below.
<p align="center">
<img src="../doc-files/default_gui.jpg" alt="Default Graphical Interface">
<p>
The VCR-like buttons control the execution of the simulation.
The buttons and their functions are
<p>
<table align="center" border="1" cellspacing="0" cellpadding="3" width="90%">
  <tr>
    <td><img src="../doc-files/play.png" alt="Play Button"></td>
    <td>Start or resume the simulation</td>
  </tr>
  <tr>
    <td><img src="../doc-files/pause.png" alt="Pause Button"></td>
    <td>Pause the simulation.
      This button replaces the play button while the simulation is running.
    </td>
  </tr>
   <tr>
    <td><img src="../doc-files/next.png" alt="Run-until Button"></td>
    <td>Display or set the last value of simulation time.
      See {@link org.mitre.sim.Simulation#setTimeLast(double) Simulation.setTimeLast(double)}.
    </td>
   </tr>
  <tr>
    <td><img src="../doc-files/stop.png" alt="Stop Button"></td>
    <td>Terminate the application abruptly by calling <code>System.exit(0)</code>.
      No <a href="#Notification">completion notification</a> occurs.
    </td>
  </tr>
</table>
<p>
<a name="SimulationTime"/>
<h3>Simulation Time</h3>

The <b>Simulation Time</b> field is updated as the simulation progresses;
by default it is displayed as a double value with up to 7 digits
to the right of the decimal point.
The displayed simulation time format can be modified with a developer-defined formatter.
Such a formatter is a subclass of <code>java.text.Format</code>, or one of its
subclasses, such as <code>java.text.SimpleDateFormat</code>.
The subclass must define the methods below.
(Not all subclasses of <code>java.text.Format</code> define both methods.)
<p>
<table align="center" border="1" cellspacing="0" cellpadding="3" width="90%">
<tr bgcolor="#ccccff" align="left" valign="top">
	<th width="45%">Method</th>
	<th width="45%">Purpose</th>
  <tr>
    <td><code>public void applyPattern(String pattern);</code></td>
    <td>Controls how the simulation time should be formatted.</td>
  </tr>
  <tr>
    <td><code>public String format(double d);</code></td>
    <td>Applies the current simulation time (the double parameter) to the format
        specified by the applyFormat method invocation.</td>
  </tr>
</table>
<p>
The developer-defined formatter class must then be referenced in <code>sim.properties</code>.
<p>
<table cols=1 border=1>
  <tr bgcolor="#99cccc"><td>
<h3>Example: Displaying Simulation Time As a Date</h3>
The <code>java.txt.SimpleDateFormat</code>
class can be extended to display the simulation time as a regular date and time.
The code below assumes that the simulation time unit is 1 second.
The developer defines the following subclass of <code>SimpleDateFormat</code>, and then references
it in the <code>sim.properties</code> file.
<blockquote>
<pre>
<b>package</b> mypackage;

<b>import</b> java.text.SimpleDateFormat;
<b>import</b> java.util.Date;
<b>public class</b> MyDateFormat <b>extends</b> SimpleDateFormat {
  // public void applyPattern(String pattern) is defined
  //  by SimpleDateFormat so there is no reason to redefine it here.
  <b>public</b> String format(double d) {
     <b>return</b>(<b>super</b>.format(<b>new</b> Date((<b>long</b>)(d * 1000))));
  }
}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The <code>sim.properties</code> file contains entries as follows:
<blockquote>
<pre>
org.mitre.sim.GUI.component.control.timeFormatter.class = mypackage.MyDateFormat
org.mitre.sim.GUI.component.control.timeFormatter.format = MM/dd/yyyy hh:mm:ss aa
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The above code and system properties yield the following at startup:
<p align="center">
<img src="../doc-files/gui_date_time.jpg" alt="GUI Date/Time"/>
<p>
</td></tr></table>
<p>
The GUI also provides control of the simulation pace.
The <b>Simulation Time Unit</b> drop-down list contains a list of common units of simulation time
The <b>Requested Pace</b> drop-down list contains common pace multipliers.
A user can set a desired pace by choosing a simulation time unit, and a requested pace.
The number displayed as <b>Actual Pace</b> is computed every second,
based on the amount of simulation time that has passed, and the current simulation time unit.

<a name="PlugInDisplays"/>
<h2>Plug-in Displays</h2>

The GUI allows for additional displays to be plugged in at runtime.
These displays implement the
{@link org.mitre.sim.gui.ComponentPanel ComponentPanel} interface.
<p>
The set of components constituting the GUI display is controlled by the
<code>org.mitre.sim.GUI.components</code> property in the <code>sim.properties</code> file.
This property lists the names of the GUI components to display.
These names are user-defined, arbitrary, and separated by spaces.
Each component is configured by a set of properties which are constructed as follows:
<blockquote>
&lt;base name&gt;<code><b>.</b></code>&lt;component name&gt;<code><b>.</b></code>&lt;component property name&gt;
</blockquote>
where &lt;base name&gt; is <code>org.mitre.sim.GUI.component</code>,
&lt;component name&gt; is the component name,
specified in the <code>org.mitre.sim.GUI.components</code> property,
and &lt;component property name&gt; is some given property defined for that component.
All components have at least one property, <code>class</code>, that determines the
classname of the component.
Component names must be unique, but multiple components may share the same component class.
<p>
The framework provides three classes that can be used as GUI components:
{@link org.mitre.sim.gui.LogDisplay},
{@link org.mitre.sim.gui.ProbeDisplay ProbeDisplay}, and
{@link org.mitre.sim.gui.SimulationPopulation SimulationPopulation}.
The capabilities and details of each display type are described in following sections.

<a name="LogDisplay"/>
<h3>Log Display</h3>

Although this simulation framework does not use the standard Java logging framework
defined in package <code>java.util.logging</code>, the simulation GUI includes
an optional component to display information logged to such loggers.
The Log Display component
(class {@link org.mitre.sim.gui.LogDisplay LogDisplay})
displays logged output from developer-defined <code>java.util.logging.Logger</code></a>
instances.
<code>LogDisplay</code> also allows capture of logged data to a file.
The <code>LogDisplay</code> functions as a <code>java.util.logging.Handler</code>
to a <code>java.util.logging.Logger</code>.
<p>
<code>LogDisplay</code> uses properties defined in <code>sim.properties</code>.
Some of these are required if <code>LogDisplay</code> is to be used.
Properties relevant to <code>LogDisplay</code> are summarized below.
<p>
<table align="center" border="1" cellspacing="0" cellpadding="3" width="90%">
<tr bgcolor="#ccccff" align="left" valign="top">
	<th width="20%">Component Property Name</th>
	<th width="70%">Purpose</th>
  <tr>
    <td><code>logger.name</code></td>
    <td>Name of the logger.
      This is the parameter typically passed to the
      <code>Logger.getLogger(String name)</code> method.
      <b>Required</b></td>
  </tr>
  <tr>
    <td><code>handler.level</code></td>
    <td>Initial level that the LogDisplay Handler uses.
      Default is <code>OFF</code>.</td>
  </tr>
  <tr>
    <td><code>handler.formatter.class</code></td>
    <td>Formatter to use for this Handler.
      Default is
      {@link org.mitre.sim.util.BasicFormatter},
      and it is recommended that this not be changed.
      This formatter uses the <code>java.text.MessageFormat</code> to format the message,
      and is easily customized.
      See {@link org.mitre.sim.util.BasicFormatter} for more information.</td>
  </tr>
  <tr>
    <td>handler.formatter.format</td>
    <td>Desired format for a log message.
      This is only used if the <code>handler.formatter.class</code>
      is {@link org.mitre.sim.util.BasicFormatter}.
      See {@link org.mitre.sim.util.BasicFormatter} for example message formats.</td>
  </tr>
  <tr>
    <td>handler.maximumLogRecords</td>
    <td>Maximum number of log records to keep --
      total number of log records maintained in the window.
      This number should be kept small,
      because <code>javax.swing.TextArea</code> implementations are often slow
      when processing a large amount of data.
      The default value for this field is 100.
      A negative or zero value sets the value to 1.
      This value only pertains to log records displayed in the GUI,
      and not to log records saved to a file.</td>
  </tr>
</table>
<p>
<table cols=1 border=1>
  <tr bgcolor="#99cccc"><td>
<h3>Example: Use of LogDisplay</h3>
This example defines two <code>LogDisplay</code> components
called  <code>MyLogger</code> and <code>MyLogger2</code>, and two <code>java.util.logging.Logger</code>
instances called <code>TestLogger</code> and <code>TestLogger2</code>.
<blockquote>
<pre>
<b>import</b> org.mitre.sim.*;
<b>import</b> java.util.logging.Logger;
<b>public class</b> MySimulation <b>extends</b> Simulation {

  <b>public static void</b> main(String[] args) {
    <b>new</b> MySimulation().{@link org.mitre.sim.Simulation#setVisible(boolean) setVisible(true)};
    Logger.getLogger("TestLogger").info("Test Message 1");
    Logger.getLogger("TestLogger2").info("Test Message 2");
  }
}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The following entries in <code>sim.properties</code> work with the code above.
<blockquote>
<pre>
org.mitre.sim.GUI.components = MyLogger MyLogger2
org.mitre.sim.GUI.component.MyLogger.class = org.mitre.sim.gui.LogDisplay
org.mitre.sim.GUI.component.MyLogger.logger.name = TestLogger
org.mitre.sim.GUI.component.MyLogger.handler.level = INFO
org.mitre.sim.GUI.component.MyLogger.handler.formatter.format
  = {0,date,MMM d, yyyy} {0,time,h:mm:ss a} {1} {2}'\n'{3}: {4}

org.mitre.sim.GUI.component.MyLogger2.class = org.mitre.sim.gui.LogDisplay
org.mitre.sim.GUI.component.MyLogger2.logger.name = TestLogger2
org.mitre.sim.GUI.component.MyLogger2.handler.level = INFO
org.mitre.sim.GUI.component.MyLogger2.handler.formatter.format = {4}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The code and properties above combine to create displays like these below.
<p align="center">
<img src="../doc-files/gui_logdisplay1.jpg" alt="Log Display 1">
<p align="center">
<img src="../doc-files/gui_logdisplay2.jpg" alt="Log Display 2">
</td></tr></table>

<a name="ProbeDisplay"/>
<h3>Probe Display</h3>
Probes
(component class {@link org.mitre.sim.gui.ProbeDisplay ProbeDisplay})
allow observation of simulation variables while the simulation is running.
They can also be used to configure a simulation prior to execution.
The Probe Display Control displays a probe for each JavaBean in the simulation.
According to the
<a href="http://java.sun.com/products/javabeans/docs/">JavaBeans Specification</a>,
a JavaBean is an object that defines
<i>getter</i> and <i>setter</i>
methods for its property fields.
The Probe Display discovers JavaBeans in the simulation and displays
corresponding probes.
<p>
<table cols=1 border=1>
  <tr bgcolor="#99cccc"><td>
<h3>Example: Use of ProbeDisplay</h3>
This example defines three properties:
<code>numEntities</code>, <code>color</code>, and <code>configFile</code>.
The entries in <code>sim.properties</code> configure a Probe display that
allows the user to examine and modify the JavaBeans properties.
The example also includes a Log display for a developer-defined logger;
this display is not necessary for the functioning of the Probe display.
<blockquote>
<pre>
import org.mitre.sim.*;
import java.util.logging.Logger;
import java.awt.Color;
import java.io.File;

public class MySimulation extends Simulation {
  int numEntities;
  Color color = Color.blue;
  File configFile;

  public void initialize() {
  }

  // Define "getter" and "setter" methods for the <b>numEntities</b> property
  <b>public int getNumEntities() {
    return(numEntities);
  }
  public void setNumEntities(int i) {
    numEntities = i;
  }
  </b>
  // Define the <b>color</b> property "getter".  This is a read-only property,
  // that is, there is no "setter" method

  <b>public Color getColor() {
    return(color);
  }
  </b>
  // Define "getter" and "setter" methods for the <b>configFile</b> property.
  <b>public File getConfigFile() {
    return(configFile);
  }
  public void setConfigFile(File f) {
    configFile = f;
  }
  </b>
  public static void main(String[] args) {
    new MySimulation().setVisible(true);
    Logger.getLogger("TestLogger").info("Test Message 1");
  }
}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The code above works with the following <code>sim.properties</code> entries.
<blockquote>
<pre>
org.mitre.sim.GUI.components = Probe
org.mitre.sim.GUI.component.Probe.class = org.mitre.sim.gui.ProbeDisplay
</pre>
</blockquote>
The following properties are associated with the LogDisplay in this example.
<blockquote>
<pre>
org.mitre.sim.GUI.component.MyLogger.class = org.mitre.sim.gui.LogDisplay
org.mitre.sim.GUI.component.MyLogger.logger.name = TestLogger
org.mitre.sim.GUI.component.MyLogger.handler.level = INFO
org.mitre.sim.GUI.component.MyLogger.handler.formatter.format
  = {0,date,MMM d, yyyy} {0,time,h:mm:ss a} {1} {2}'\n'{3}: {4}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The code and properties file combine to produce the following display.
<p align="center">
<img src="../doc-files/gui_probe.jpg" alt="Probed Display"><br><br>
<p>
Because <b>color</b> is a read-only property, its value cannot be changed from the GUI.
However, the value of <b>numEntities</b> can be changed by typing a new number in the
corresponding text field.
Similarly, a file dialog appears when the field for the file name is clicked
next to the <b>configFile</b> label.
Afterwords, the control panel looks similar to the following:
<p align="center">
<img src="../doc-files/gui_probe2.jpg" alt="Edited Probe Display"><br>
<p>
</td></tr></table>
<p>
ProbeDisplay automatically probes the Simulation instance.
However, using the Population display, probes on Entities can be performed as well.
<p>
The ProbeDisplay class recognizes the properties listed below.
<p>
<table align="center" border="1" cellspacing="0" cellpadding="3" width="90%">
  <tr bgcolor="#ccccff" align="left" valign="top">
	<th width="20%">Component Property Name</th>
	<th width="70%">Purpose</th>
  </tr>
  <tr>
    <td><code>updateFrequency</code></td>
    <td>How frequently each JavaBean is probed.
      Displayed values are updated at the stated interval.
      This number is in milliseconds, and defaults to 1000. </td>
  </tr>
</table>

<a name="PopulationDisplay"/>
<h3>Population Display</h3>
The Population Display
(component class {@link org.mitre.sim.gui.SimulationPopulation SimulationPopulation})
shows the hierarchy of registered entities during a running simulation.
This hierarchy is displayed in a tree form, with classes of entities as nodes
and instances as leaves.
Any instance can be right-clicked to display Java Beans properties for that
instance.
Selecting a Bean adds that Bean to the Probe Display.
Populations are only available after the simulation has been started.
<p>
<table cols=1 border=1>
  <tr bgcolor="#99cccc"><td>
<h3>Example: Use of Population Display</h3>
This example simulation has two Entity subclasses,
each subclass with a single Bean property defined whose value is set
to change every simulated second.
This example incorporates a Population display, to show the entities that can be probed,
and a Probe display, to show the JavaBeans property values of the probed entities.
Typically both displays are used together.
The example also includes a Log display for a developer-defined logger;
this display is not necessary for the functioning of the other displays.
<blockquote>
<pre>
import org.mitre.sim.*;
import java.util.Random;
import java.util.logging.Logger;
import java.awt.Color;
import java.io.File;

public class MySimulation extends Simulation {
  public void initialize() {
    register(new ColorEntity("Color Entity"));
    register(new IntegerEntity("Integer Entity"));
  }

  public static void main(String[] args) {
    new MySimulation().setVisible(true);
    Logger.getLogger("TestLogger").info("Test Message 1");
  }
  public class ColorEntity extends Entity {
    Color c = Color.black;
    Random r = new Random();

    public ColorEntity(String name) {
      super(name);
    }

    public Color getColor() {
      return(c);
    }

    public void agenda() {
      while (true) {
	  c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256));
	waitForTime(1.0);
      }
    }
  }

  public class IntegerEntity extends Entity {
    int i = 0;
    Random r = new Random();

    public IntegerEntity(String name) {
      super(name);
    }

    public int getInteger() {
      return(i);
    }

    public void agenda() {
      while (true) {
	i = r.nextInt();
	waitForTime(1.0);
      }
    }
  }
}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
Entries in the <code>sim.properties</code> relevant to the Population Display are
shown below.
<blockquote>
<pre>
org.mitre.sim.GUI.components = Probe Population
org.mitre.sim.GUI.component.Probe.class
  = org.mitre.sim.gui.ProbeDisplay
org.mitre.sim.GUI.component.Population.class
  = org.mitre.sim.gui.SimulationPopulation
</pre>
</blockquote>
Below are other entries in<code>sim.properties</code> relevant to the LogDisplay
in this example.
<blockquote>
<pre>
org.mitre.sim.GUI.components = MyLogger Probe Population
org.mitre.sim.GUI.component.MyLogger.class
  = org.mitre.sim.gui.LogDisplay
org.mitre.sim.GUI.component.MyLogger.logger.name = TestLogger
org.mitre.sim.GUI.component.MyLogger.handler.level = INFO
org.mitre.sim.GUI.component.MyLogger.handler.formatter.format
  = {0,date,MMM d, yyyy} {0,time,h:mm:ss a} {1} {2}'\n'{3}: {4}
</pre>
</blockquote>
</td></tr>
<tr bgcolor="#99cccc"><td>
The code and system properties displayed above combine to yield displays like the following.
<p align="center">
<img src="../doc-files/gui_populations1.jpg" alt="Populations1">
<p align="center">
<img src="../doc-files/gui_populations2.jpg" alt="Populations2">
<p>
</td></tr></table>
<p>
The Population Display class recognizes the properties listed in the table below.
<p>
<table align="center" border="1" cellspacing="0" cellpadding="3" width="90%">
  <tr bgcolor="#ccccff" align="left" valign="top">
	<th width="20%">Component Property Name</th>
	<th width="70%">Purpose</th>
  </tr>
  <tr>
    <td><code>updateFrequency</code></td>
    <td>How frequently each JavaBean is probed.
      Displayed values are updated at the stated interval.
      This number is in milliseconds, and defaults to 1000. </td>
  </tr>
</table>


<p><p><hr size ="10" color="gray"/>
<a name="PropertyFileParameters"/>
<h2>Property File Parameters</h2>
The GUI obtains runtime parameters from the same Java properties file as the simulation infrastructure.
The name of the properties file is <code>sim.properties</code> and
is located in CVS at <code>CVSRoot/sim/resources/sim.properties</code>.
To be accessible at runtime, a <code>resources</code> directory containing <code>sim.properties</code>
must exist at the root of the class file structure.
This occurs two ways:
<ul>
  <li>During development in the <code>CVSRoot/sim/classes/resources</code> directory
  <li>At runtime in the root of the <code>sim.jar</code> archive.
</ul>
The Ant script <code>CVSRoot/sim/build.xml</code> moves
the <code>resources</code> directory to these two places.
Ant target <code>build</code> copies the <code>resources</code> directory to
the <code>CVSRoot/sim/classes</code> directory.
Ant target <code>jar</code> copies the <code>resources</code> directory into the <code>sim.jar</code> archive.
<p>
The property file contents that relate to the GUI are described below:
<br>
<br>
<table align="center" border="1" cols="3" cellspacing="0" cellpadding="3" width="90%">
  <tr bgcolor="#ccccff" align="left" valign="top">
    <th>Property Name</th>
    <th>Description</th>
    <th>Default Value</th>
  </tr>
  <tr>
    <td>org.mitre.sim.GUI.components</td>
    <td>The components to show on the Simulation's GUI.</td>
    <td>control</td>
  </tr>
  <tr>
    <td>org.mitre.sim.GUI.component. <b>&lt;component name&gt;</b>.class</td>
    <td>The java class to load for a particular graphical component</td>
    <td>[control] = org.mitre.sim.gui.SimControl</td>
  </tr>
  <tr>
    <td>org.mitre.sim.GUI.component. <b>&lt;component name&gt;</b>.*</td>
    <td>Properties specific to a particular GUI component</td>
    <td>N/A</td>
  </tr>
  <tr>
    <td>org.mitre.sim.GUI.component. control.timeFormatter.class</td>
    <td>The time format class to use when displaying the simulation time</td>
    <td>java.text.DecimalFormat</td>
  </tr>
  <tr>
    <td>org.mitre.sim.GUI.component. control.timeFormatter.format</td>
    <td>Format used to convert the simulation time into a displayable string</td>
    <td>#########0.0######</td>
  </tr>
</table>
<br>

<p><img src="../doc-files/mitre_logo.gif"><br>
<font size=-2>Copyright &copy; 2003-2004 The MITRE Corporation</font>
</body>
